<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var countDigitOne = function (n) {
      let count = 0;
      for (i = 1; i <= n; i++) {
        let cur = i;
        while (cur !== 0) {
          if (cur % 10 === 1) count++;
          cur = Math.floor(cur / 10);
        }
      }
      return count;
    };
    console.log(countDigitOne(13333));
  </script>
</body>

</html>